<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');
	
	if (isset($_GET['building_id']))
	{
		$building_id = mysql_real_escape_string(strip_tags($_GET['building_id']));
	}
	if (isset($_GET['schedule_id'])) {
		$schedule_id = mysql_real_escape_string(strip_tags($_GET['schedule_id']));
	}
	if (isset($_GET['semester_id']))
	{
		$semester_id = mysql_real_escape_string(strip_tags($_GET['semester_id']));
	}
	
	if (isset($_POST['submitDelete']))
	{
		$query = "delete from schedule where id = '$schedule_id'";
		mysql_query($query);
		
		header("Location:postSchedule.php?building_id=$building_id&semester_id=$semester_id");
		exit(0);
	}
	
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');
	?>
	
    <p><a href="postSchedule.php?building_id=<?php echo $building_id; ?>&amp;semester_id=<?php echo $semester_id; ?>">&lt;&lt; Back to Full Schedule</a></p>
    
    <h1>Remove Course From Schedule</h1>
    
	<p>Are you sure you want to remove this course section from the schedule?</p>
	
	<?php
	
	$query = "SELECT *, b.abbreviation AS b_abbrev, csub.abbreviation AS sub_abbrev, cs.id AS course_section_id
			  FROM schedule s
			  JOIN course_sections cs ON cs.id = s.course_section_id
			  JOIN course_section_mapping csm ON csm.course_section_id = cs.id
			  JOIN courses c on c.id = csm.course_id
			  JOIN course_subjects csub ON csub.id = c.course_subject_id
			  JOIN instructors i ON i.id = cs.instructor_id
			  JOIN classrooms cr ON cr.id = s.classroom_id
			  JOIN buildings b ON b.id = cr.building_id
			  JOIN time_slots ts ON ts.id = s.time_slot_id
			  WHERE s.id = '$schedule_id'
			  GROUP BY cs.id ";
			  
			  

				   
			  
	$result = mysql_query($query);
	
	$row = mysql_fetch_assoc($result);
	//echo $row[];
	$course_section_id = $row['course_section_id'];
	//print_r($row);
		
	
	
	$q2 = "SELECT *
            FROM course_sections cs
            JOIN course_section_mapping csm ON csm.course_section_id = cs.id
            JOIN courses c on c.id = csm.course_id
            JOIN course_subjects csub ON csub.id = c.course_subject_id
            WHERE cs.id = '$course_section_id'
            ORDER BY c.course_number ASC";
	echo "<p><strong>";
	
	$r2 = mysql_query($q2);
	$num_courses = mysql_num_rows($r2);
	$count = 0;
	while($row2 = mysql_fetch_assoc($r2))
	{
		$count++;
		echo $row2['abbreviation'].' '.$row2['course_number'].' - ';
		if (strlen($row2['section_number']) == 1)
			{echo "00".$row2['section_number'];}
		else if (strlen($row2['section_number']) == 2)
			{echo "0".$row2['section_number'];}
		else
			{echo $row['section_number'];}
		if ($row2['honors_program'] == 1  && $row2['course_number'] < 5000)
		{
			echo "<br/>".$row2['abbreviation'].' '.$row2['course_number'].' - 099';	
		}
		
		if ($count != $num_courses)
		{
			echo "<br />";
		}
	}
	echo "</strong></p>\n";
?>	
	
	<form action="delete_course.php?building_id=<?php echo $building_id; ?>&amp;semester_id=<?php echo $semester_id; ?>" method ="post">

	<input type="hidden" name = "schedule_id" value="<?php echo $schedule_id; ?>">
	<input type="hidden" name = "building_id" value="<?php echo $building_id; ?>">
	<p><input type="submit" name="submitDelete" value="Confirm"></p>

	</form>

			
<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>
			
			
		
			
			
			

